package HibernateOrederManagement.command;

import java.util.HashMap;
import java.util.Map;

import HibernateOrederManagement.command.impl.ExitCommand;
import HibernateOrederManagement.command.impl.HelpCommand;
import HibernateOrederManagement.command.impl.LoginCommand;
import HibernateOrederManagement.command.impl.RegisterCommand;

public class SystemCommandFactory extends CommandFactory{
	
	private static Map<CommandCode,Class<? extends Command>> systemCommandMap =new HashMap<>();
	
	static {
		systemCommandMap.put(CommandCode.HELP, HelpCommand.class);
		systemCommandMap.put(CommandCode.EXIT, ExitCommand.class);
		systemCommandMap.put(CommandCode.LOGIN, LoginCommand.class);
		systemCommandMap.put(CommandCode.REGISTER, RegisterCommand.class);	
	}

	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<?extends Command>cmdClass =systemCommandMap.get(cmdCode);
		
		if(cmdClass!=null){	
			try {
				return cmdClass.newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

}
